package com.yiren.dbaa.module.practice_set.site.view.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.yiren.dbaa.R;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * @author lwb
 * @date : 2022/9/19 10:18
 * @description: 练车设置名字列表适配器
 */
public class CarPracticeSetNameAdapter extends BaseAdapter {

    private Context context;
    private List<String> list;
    public int mSelect = 0;

    public CarPracticeSetNameAdapter(Context context, List<String> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (null == convertView) {
            convertView = View.inflate(context, R.layout.item_practice_set_name, null);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        holder.tvName.setText(list.get(position));
        if (mSelect == position) {
            holder.rlName.setBackgroundResource(R.color.blue_select_bg);
            holder.tvName.setTextColor(context.getResources().getColor(R.color.blue_select_text));
            holder.ivRbg.setVisibility(View.VISIBLE);
        } else {
            holder.rlName.setBackgroundResource(R.color.white);
            holder.tvName.setTextColor(context.getResources().getColor(R.color.gray_text));
            holder.ivRbg.setVisibility(View.INVISIBLE);
        }
        return convertView;
    }

    static class ViewHolder {
        @BindView(R.id.rl_name)
        RelativeLayout rlName;
        @BindView(R.id.tv_name)
        TextView tvName;
        @BindView(R.id.iv_rbg)
        ImageView ivRbg;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }

    public void changeSelected(int position) {
        if (position != mSelect) {
            mSelect = position;
            notifyDataSetChanged();
        }
    }

}